const express = require('express')

const app = express()

app.listen(22064, () => {
    console.log('Server is running at http://localhost:22064')
})

const cors = require('cors')
app.use(cors({
    origin: '*'
}))

const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({extended: false}))
// 解析json
app.use(bodyParser.json())


const router = require('./router/index.js')
app.use(router)

app.use('/avatar', express.static('public'))
app.use((req, resp, next) => {
    resp.status(404).json({
        code: 404,
        msg: 'Not Found'
    })
})

app.use((err, req, resp, next) => {
    resp.status(500).json({
        code: 500,
        msg: '请求错误，错误为：' + err.message
    })
})